<?php
/*
# ------------------------------------------------------------------------
# JA Job Board Package
# ------------------------------------------------------------------------
# Copyright (C) 2004-2010 JoomlArt.com. All Rights Reserved.
# @license GNU/GPLv3 http://www.gnu.org/licenses/gpl-3.0.html
# Author: JoomlArt.com
# Websites: http://www.joomlart.com - http://www.joomlancers.com.
# ------------------------------------------------------------------------
*/
  defined('_JEXEC') or die('Retricted Access');
  
  JHTML::_('behavior.tooltip');
?>
<script language="javascript" type="text/javascript">
function display_item(id)
{
	obj_item = document.getElementById(id);
	
	if (obj_item.style.display=='none')
		obj_item.style.display='block';
	else
		obj_item.style.display='none';		
}
</script>
<form name="adminForm" action="index.php" method="post">
<table width="100%">
	<tr>
	
		<td width="80%" valign="top">    
	<div style="width:100%;">
		<table>
			<tr>
				<td align="left" width="100%">
					<?php echo JText::_( 'Filter' ); ?>:
					<input type="text" name="search" id="search" value="<?php echo $this->lists['search'];?>" class="text_area" onchange="document.adminForm.submit();" />
					<button onclick="this.form.submit();"><?php echo JText::_( 'Go' ); ?></button>
					<button onclick="document.getElementById('search').value=''; document.getElementById('filter_form').value=''; document.getElementById('filter_table').value=''; this.form.submit();"><?php echo JText::_( 'Reset' ); ?></button>
				</td>
				<td nowrap="nowrap">
				<?php echo $this->lists['forms'];?>&nbsp;
				<?php echo $this->lists['tables'];?>
			</td>

			</tr>
		</table>

		<table class="adminlist">
        	<thead>
				<tr>
					<th width="20">
						<?php echo JText::_( 'NUM' ); ?>
					</th>
					<th width="20">
						<input type="checkbox" name="toggle" value="" onclick="checkAll(<?php echo count($this->items); ?>);" />
					</th>
					
					<th width="25%" nowrap="nowrap">
						<?php echo JHTML::_('grid.sort',  JText::_('Field Label'), 'f.label', @$this->lists['order_Dir'], @$this->lists['order'] ); ?>
					</th>
					<th width="5%" nowrap="nowrap">
						<?php echo JHTML::_('grid.sort',  JText::_('Published'), 'f.published', @$this->lists['order_Dir'], @$this->lists['order'] ); ?>
					</th>
					<th width="15%" nowrap="nowrap">
						<?php echo JHTML::_('grid.sort',   JText::_('Field name'), 'f.field_name', @$this->lists['order_Dir'], @$this->lists['order'] ); ?>
					</th>
					<th width="13%" class="title">
						<?php echo JHTML::_('grid.sort',   JText::_('Form name'), 'f.form_id', @$this->lists['order_Dir'], @$this->lists['order'] ); ?>
					</th>
					<th width="13%" class="title">
						<?php echo JHTML::_('grid.sort',   JText::_('Table name'), 'f.table_name', @$this->lists['order_Dir'], @$this->lists['order'] ); ?>
					</th>
					<th width="10%" nowrap="nowrap">
						<?php echo JHTML::_('grid.sort',   JText::_('Field Ordering'), 'f.field_ordering', @$this->lists['order_Dir'], @$this->lists['order'] ); ?>
						<?php echo JHTML::_('grid.order',  $this->items ); ?>  
					</th>
					<th width="12%">
						<?php echo JHTML::_('grid.sort',   JText::_('Field type'), 'f.field_type', @$this->lists['order_Dir'], @$this->lists['order'] ); ?>
					</th>
					<th width="5%" class="title">
						<?php echo JHTML::_('grid.sort',   JText::_('Is required'), 'f.is_required', @$this->lists['order_Dir'], @$this->lists['order'] ); ?>
						
					</th>
					
					<th width="5%" class="title">
						<?php echo JHTML::_('grid.sort',   JText::_('Field State'), 'f.field_state', @$this->lists['order_Dir'], @$this->lists['order'] ); ?>											
					</th>
					
					<th width="5%" class="title">
						<?php echo JHTML::_('grid.sort',   JText::_('System Field'), 'f.is_system', @$this->lists['order_Dir'], @$this->lists['order'] ); ?>											
					</th>
				</tr>
			</thead>
			<tbody>
        	<?php
        	$items = $this->items;
        	$k = 0;
        	$orderNo = 0;
        	$currentTable = '';
        	$formslist = JobBoardConstant::getFormList();
            $tableList = JobBoardConstant::getTableList();
            $FieldTypeList = JobBoardConstant::getFieldTypeList();
        	for($i = 0, $n = count($items); $i < $n; $i++, $orderNo++){
        		$item = $items[$i];
        		$checked 	= JHTML::_('grid.checkedout',   $item, $i );
        		$isFirst = false;
        		$isLast = false;
        		$required 	= $this->required($item, $i);
        		
        		if($currentTable != $item->table_name){
        		    $currentTable = $item->table_name;
        		    $isFirst = true;
        		    $orderNo = 0;
				} 
				
				if($i == $n -1 || ($currentTable != $items[$i+1]->table_name)){
        		    $isLast = true;
				}
				
				if (!$item->is_system)
					$published 	= JHTML::_('grid.published', $item, $i );
				else 
					$published 	= '<img onclick="alert(\'This is system field, you cannot UnPublish this field.\');" border="0" alt="Published" src="images/tick.png"/>';
        		?>
        		<tr class="row<?php echo $k; ?> <?php if(in_array($item->field_state, array('mod', 'ins'))) echo 'warning editlinktip hasTip';?>" <?php if(in_array($item->field_state, array('mod', 'ins'))){?> title="<?php echo htmlspecialchars(JText::_( 'The row(s) are bold red will not be displayed outside the front-end. Please click on the "DB rebuild" button to change the status of these items' )); ?>" <?php }?>>
            		<td onclick="display_item('update_table'+<?php echo $i; ?>)" style="width:10;" align="center"><?php echo $this->pagination->getRowOffset($i); ?></td>
            		
            		<td width="10" align="center"><?php echo $checked; ?></td>
            		
            		
            		<td>
            		<span class="editlinktip hasTip" title="<?php echo JText::_( 'Edit Field' );?>::<?php echo $item->label; ?>">
					<a href="<?php echo JRoute::_( 'index.php?option='. $this->lists['option'] .'&view=jamanagefields&task=edit&cid[]='.$item->id ); ?>"><?php echo $item->label; ?></a></span>
            		</td>
            		<td width="10" align="center"><?php echo $published; ?></td>
            		<td><?php echo $item->field_name; ?></td>
            		<td>            			
            			<?php echo isset($formslist[$item->form_id])?$formslist[$item->form_id]:$formslist[3]; ?>
            				
            		</td>
            		<td><?php echo isset($tableList[$item->table_name])?$tableList[$item->table_name]:$tableList['ja_jobs']; ?></td>
            		<td class="order" nowrap="nowrap">
						<span><?php echo $this->pagination->orderUpIcon( $i, !$isFirst, 'orderup', 'Move Up', $this->ordering); ?></span>
						<span><?php echo $this->pagination->orderDownIcon( $i, $orderNo + 1, !$isLast, 'orderdown', 'Move Down', $this->ordering ); ?></span>
						<?php $disabled = $this->ordering ?  '' : 'disabled="disabled"'; ?>
						<input type="text" name="field_ordering[]" size="5" value="<?php echo $item->field_ordering; ?>" <?php echo $disabled ?> class="text_area" style="text-align: center" />
					</td>
            		<td  align="left" width="100"><?php echo $FieldTypeList[$item->field_type]; ?></td>
            		<td align="center">
            			&nbsp;
            			<?php echo $required; ?>
            		</td>
            		
					<td align="center">
            			<?php echo JobBoardConstant::getFieldStateList($item->field_state); ?>
            		</td>
					
					<td align="center">
						<!--<?php if($item->is_system){?>
						<a title="<?php echo JText::_('Field not system')?>" onclick="return listItemTask('cb<?php echo $i?>','system')" href="javascript:void(0);">
							<img border="0" alt="<?php echo JText::_('Field not system')?>" src="images/tick.png"/>
						</a>
						<?php }else{?>
						<a title="<?php echo JText::_('Field system');?>" onclick="return listItemTask('cb<?php echo $i?>','notsystem')" href="javascript:void(0);">
							<img border="0" alt="<?php echo JText::_('Field system');?>" src="images/publish_x.png"/>
						</a>
						<?php }?>-->
						
						<?php if($item->is_system){?>
						<?php echo JText::_('Yes')?>
						<?php }else{?>
						<?php echo JText::_('No')?>
						<?php }?>
            		</td>
            	</tr>
        	<?php
        	if (in_array($item->field_state, array('mod', 'ins')))
        	{
        	?>
        		<tr class="row<?php echo $k; ?>">
        			<td colspan="12">
        				<font color="Red">
        					<?php echo JText::_('The row(s) are bold red will not be displayed outside the front-end. Please click on the "DB rebuild" button to change the status of these items')?>
        				</font>
        			</td>
        		</tr>
	        	<tr class="row<?php echo $k; ?>">
	        	
	        		<td colspan="4">
	        			<?php if ($item->old_table_name!=$item->table_name) {?>
		        			<b><?php echo JText::_('Old table name')."  /  ".JText::_('New table name'); ?>:&nbsp;&nbsp;</b> 
		        			<del><?php echo $item->old_table_name; ?></del>  /  <font color="Red"><?php echo $item->table_name; ?></font>
	        			<?php } else { ?>
	        				<b> <?php echo JText::_('Table name'); ?>:&nbsp;&nbsp;</b><?php echo JText::_('Not changed'); ?>
	        			<?php } ?>
	        		</td>
	        		<td colspan="3">
	        			<?php if ($item->old_field_name!=$item->field_name) {?>
		        			<b><?php echo JText::_('Old field name')."  /  ".JText::_('New field name'); ?>:&nbsp;&nbsp;</b> 
		        			<del><?php echo $item->old_field_name; ?></del>  /  <font color="Red"><?php echo $item->field_name; ?></font>
	        			<?php } else { ?>
	        				<b> <?php echo JText::_('Field name'); ?>:&nbsp;&nbsp;</b><?php echo JText::_('Not changed'); ?>
	        			<?php } ?>
	        		</td>
	        		<td colspan="3">
	        			<?php if ($item->old_field_type!=$item->field_type) {?>
		        			<b><?php echo JText::_('Old type')."  /  ".JText::_('New type'); ?>: &nbsp;&nbsp;</b>
		        			<del><?php echo $FieldTypeList[$item->old_field_type]; ?></del>  /  <font color="Red"><?php echo $FieldTypeList[$item->field_type]; ?></font>
	        			<?php } else { ?>
	        				<b> <?php echo JText::_('Field type'); ?>:&nbsp;&nbsp;</b><?php echo JText::_('Not changed'); ?>
	        			<?php } ?>
	        		</td>
   					<td colspan="2">
   						<a href="<?php JURI::base()?>index.php?option=<?php echo $this->lists['option']; ?>&view=jamanagefields&task=reverse&cid[]=<?php echo $item->id; ?>" onclick="return confirm('<?php echo htmlspecialchars(JText::_('Are you sure to reverse this field? If you choose ok, the system will restore field name and field type only, other parameters will be subject to latest change. Please go to field customization area to check again'))?>')">
   							<?php echo JText::_('Undo'); ?>
   						</a> &nbsp;/&nbsp; 
   						<a href="<?php JURI::base()?>index.php?option=<?php echo $this->lists['option']; ?>&view=jamanagefields&task=updatetable&cid[]=<?php echo $item->id; ?>"><?php echo JText::_('Rebuild db'); ?></a>
   					</td>
	        						
	        	</tr>
	        	
        	<?php 	
        	}
        	?>
        	<?php 
        		$k = 1 - $k;
			}
        	?>
        	<tbody>
        	<tfoot>
				<tr>
					<td align="center" colspan="12">
						<div style="margin:auto"><center><?php echo $this->pagination->getListFooter(); ?></center>			
						<br/></div>
						<div style="clear:both">
						<img src="<?php JURI::base()?>templates/khepri/images/notice-note.png" align="Note"/>
						<?php echo JText::_('The row(s) are bold red will not be displayed outside the front-end. Please click on the "DB rebuild" button to change the status of these items')?>			
						</div>
					</td>
				</tr>			
			</tfoot>
		</table>
	</div>
	</td>
	</tr>
	</table>
	
	<input type="hidden" name="option" value="<?php echo $this->lists['option']; ?>" />
	<input type="hidden" name="view" value="jamanagefields" />
	<input type="hidden" name="task" value="" />
	<input type="hidden" name="boxchecked" value="0" />
	<input type="hidden" name="filter_order" value="<?php echo $this->lists['order']; ?>" />
	<input type="hidden" name="filter_order_Dir" value="<?php echo $this->lists['order_Dir']; ?>" />
	<?php echo JHTML::_( 'form.token' ); ?>	
 </form>
